// 注册
Vue.component('verification_code', {
	props: ['Tel','Intervals','Get_code','Wait_code','type',"is_exsist"],
	template: '<button @click.prevent="getCode" :class=\'[{"btn-base":isCode}]\' class="btn no_padding btn-block" style="height:34px;">{{time}}{{code_tips}}</button>',
	data: function() {
		return {
			time: '',
			code_tips: this.Get_code || '获取验证码',
			intervals:this.Intervals || 60,
			get_code:this.Get_code || '获取验证码',
			wait_code:this.Wait_code || '秒后获取',
			url:{
				getRegCode: '/api/Home/CheckMobileMsgCode',
				getUserCode: '/api/Home/CheckMobileMsgCodeForUserID',
			},
			code:'', //验证码
		}
	},
	mounted: function() {
		console.log(this.tel)
		console.log(this.Get_code)
	},
	computed: {
		isCode: function() {
			var tel = /^1\d{10}$/
			return(tel.test(this.Tel) && this.time == '')
//			if(!this.Tel){
//				return(this.time == '')
//			}else{
//				return(tel.test(this.Tel) && this.time == '')
//			}
			
			
		}
	},
	methods: {
		getCode: function() {
			var that = this			
			if(!that.isCode) {
				return
			}
			//获取验证码
			that.time = this.intervals
			that.isCode = false
			that.code_tips = that.wait_code			
			var timer = setInterval(function() {
				that.time--
					if(that.time < 1) {
						clearInterval(timer);
						that.time = ''
						that.isCode = true
						that.code_tips = that.get_code
					}
			}, 1000)
			var url = this.url.getUserCode;
			if(this.type==0)
				var url = this.url.getRegCode;
			//发送短信
			globalData.ajaxPost(url, {
				"Mobile": that.Tel,
				"MsgType": 1
			}, function(res) {
				if(res.data.length == 4){
					that.code = res.data
					globalData.setStorage('code',res.data)
				}
			})
		},
		getGisterCode:function(){
			
		}
	}
})